package config

import (
	"log"

	"github.com/kelseyhightower/envconfig"
)

type Config struct {
	ServerPort      string `env:"SERVER_PORT" default:"8080"`
	DBURL           string `env:"DB_URL" default:"postgres://gdrive:secret123@localhost:5432/gdrive?sslmode=disable"`
	RedisAddr       string `env:"REDIS_ADDR" default:"redis:6379"`
	MinIOEndpoint   string `env:"MINIO_ENDPOINT" default:"localhost:9000"`
	MinIOAccessKey  string `env:"MINIO_ACCESS_KEY" default:"minioadmin"`
	MinIOSecretKey  string `env:"MINIO_SECRET_KEY" default:"minioadmin"`
	MinIOBucketName string `env:"MINIO_BUCKET" default:"gdrive-files"`
	JWTSecret       string `env:"JWT_SECRET" default:"your-super-secret-jwt-key"`
}

// LoadConfig 从环境变量加载配置
func LoadConfig() *Config {
	var cfg Config
	err := envconfig.Process("", &cfg)
	if err != nil {
		log.Fatal("加载配置失败:", err)
	}
	return &cfg
}
